#include "StdAfx.h"
#include "CurveObj.h"
#include "CurveDisplayObj.h"


CCurveObj::CCurveObj(void)
{
	m_shapeStyle = SHAPE_CURVE;

	m_dblStartPosX = 0.0;	
	m_dblStartPosY = 0.0;	
	m_dblEndPosX = 0.0;	
	m_dblEndPosY = 0.0;	
	m_dblR=0.0;
	m_dblG=0.0;
	m_dblB=0.0;

	m_dblFirPosX = 0.0;
	m_dblFirPosY = 0.0;
	m_dblSecPosX = 0.0;
	m_dblSecPosY = 0.0;
	m_width=0.5;
}

CCurveObj::CCurveObj( CEntityObj* pParentEnt ):CShape(pParentEnt)
{
	m_shapeStyle = SHAPE_CURVE;

	m_dblStartPosX = 0.0;	
	m_dblStartPosY = 0.0;	
	m_dblEndPosX = 0.0;	
	m_dblEndPosY = 0.0;
	m_dblR=0.0;
	m_dblG=0.0;
	m_dblB=0.0;

	m_dblFirPosX = 0.0;
	m_dblFirPosY = 0.0;
	m_dblSecPosX = 0.0;
	m_dblSecPosY = 0.0;
	m_width=0.5;
}
CCurveObj::CCurveObj(const CCurveObj* pSrc ):CShape(pSrc)
{
	m_shapeStyle = pSrc->getShapeStyle();

	m_dblStartPosX = pSrc->GetStartPosX();	
	m_dblStartPosY = pSrc->GetStartPosY();	
	m_dblEndPosX = pSrc->GetEndPosX();	
	m_dblEndPosY = pSrc->GetEndPosY();	
	m_dblR=pSrc->GetColorR();
	m_dblG=pSrc->GetColorG();
	m_dblB=pSrc->GetColorB();

	m_dblFirPosX =pSrc->GetFirPosX();
	m_dblFirPosY =pSrc->GetFirPosY();
	m_dblSecPosX =pSrc->GetSecPosX();
	m_dblSecPosY =pSrc->GetSecPosY();
	m_width=pSrc->GetWidth();
}
CCurveObj::~CCurveObj(void)
{

}
void CCurveObj::Serialize( CArchive & ar )
{
	if (GetIsSvgGroundShape()||GetIsSvgComponentShape())
	{
		if (ar.IsStoring())
		{
			ar << m_dblStartPosX;	
			ar << m_dblStartPosY;	
			ar << m_dblEndPosX;	
			ar << m_dblEndPosY;	
			ar<<m_dblR;
			ar<<m_dblG;
			ar<<m_dblB;

			ar<<m_dblFirPosX;
			ar<<m_dblFirPosY;
			ar<<m_dblSecPosX;
			ar<<m_dblSecPosY;
			ar<<m_width;
		} 
		else
		{
			ar >> m_dblStartPosX;	
			ar >> m_dblStartPosY;	
			ar >> m_dblEndPosX;	
			ar >> m_dblEndPosY;	
			ar >>m_dblR;
			ar >>m_dblG;
			ar >>m_dblB;

			ar>>m_dblFirPosX;
			ar>>m_dblFirPosY;
			ar>>m_dblSecPosX;
			ar>>m_dblSecPosY;
			ar >>m_width;
		}
	}
	CShape::Serialize(ar);
}
double CCurveObj::GetStartPosX() const
{
	return m_dblStartPosX;
}
double CCurveObj::GetStartPosY() const
{
	return m_dblStartPosY;
}

double CCurveObj::GetEndPosX() const
{
	return m_dblEndPosX;
}

double CCurveObj::GetEndPosY() const
{
	return m_dblEndPosY;
}
void CCurveObj::SetStartPosX(double posX)
{
	m_dblStartPosX = posX;
}

void CCurveObj::SetStartPosY(double posY)
{
	m_dblStartPosY = posY;
}

void CCurveObj::SetEndPosX(double posX)
{
	m_dblEndPosX = posX;
}

void CCurveObj::SetEndPosY(double posY)
{
	m_dblEndPosY = posY;
}

CDisplayObj * CCurveObj::CreateDisplayObj( long lLayerId )
{
	CCurveDisplayObj *pCurveDis = new CCurveDisplayObj(this);
	pCurveDis->SetLayerId(lLayerId);
	return pCurveDis;
}


void CCurveObj::CopyDisplayObj( long lSourceLayerId, long lDestLayerId )
{
	CEntityObj::CopyDisplayObj(lSourceLayerId, lDestLayerId);
}

void CCurveObj::DeleteDisplayObj( long lLayerId )
{
	CEntityObj::DeleteDisplayObj(lLayerId);
}


void CCurveObj::CalcBox()
{
	m_minX = min(m_dblStartPosX, m_dblEndPosX);
	m_minY = min(m_dblStartPosY, m_dblEndPosY);
	m_maxX = max(m_dblStartPosX, m_dblEndPosX);
	m_maxY = max(m_dblStartPosY, m_dblEndPosY);
	double minX1(0),maxX1(0),minY1(0),maxY1(0);
	minX1=min(m_dblFirPosX,m_dblSecPosX);
	minY1=min(m_dblFirPosY,m_dblSecPosY);
	maxX1=max(m_dblFirPosX,m_dblSecPosX);
	maxY1=max(m_dblFirPosY,m_dblSecPosY);
	m_minX=min(m_minX,minX1);
	m_minY=min(m_minY,minY1);
	m_maxX=max(m_maxX,maxX1);
	m_maxY=max(m_maxY,maxY1);
}

void CCurveObj::SetColor( double colorR, double colorG, double colorB )
{
	m_dblR = colorR;
	m_dblG = colorG;
	m_dblB = colorB;
}

CObj * CCurveObj::Clone() const
{
	return new CCurveObj(this);
}
